#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int min(int a, int b) {
    return a < b ? a : b;
}

int max(int a, int b) {
    return a > b ? a : b;
}

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        int n;
        scanf("%d", &n);
        int colors[n];
        int last_occurrence[100001] = { 0 };
        for (int i = 0; i < n; i++) {
            scanf("%d", &colors[i]);
        }
        int result = 0;
        int max_steps = 0;
        for (int i = 0; i < n; i++) {
            max_steps = max(max_steps, i - last_occurrence[colors[i]]);
            last_occurrence[colors[i]] = i;
            result = max(result, min(max_steps, n - i));
        }
        printf("%d\n", result);
    }
    return 0;
}


